package com.qh.resourcehub.utils;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ApiResponse {
    private Integer retCode;  // 返回码
    private String retMsg;    // 返回消息
    private Object retData;   // 返回数据内容

    private String isSuccess; // 状态标识 (例如 "01" 成功, "02" 失败)
    private String errorMsg;  // 错误信息
    private String errorCode; // 错误代码 (如果有的话)
    private String syncRecordId; // 同步记录 ID
    private String systemCode; // 系统代码 (如果有的话)

    // 默认构造方法
    public ApiResponse(Integer retCode, String retMsg) {
        this.retCode = retCode;
        this.retMsg = retMsg;
    }

    // 带返回数据的构造方法
    public ApiResponse(Integer retCode, String retMsg, Object retData) {
        this.retCode = retCode;
        this.retMsg = retMsg;
        this.retData = retData;
    }

    // 构造返回只包含必要字段的响应（例如仅返回 "isSuccess", "errorMsg", "syncRecordId"）
    public ApiResponse(String isSuccess, String errorMsg,String errorCode, String syncRecordId) {
        this.isSuccess = isSuccess;
        this.errorMsg = errorMsg;
        this.errorCode=errorCode;
        this.syncRecordId = syncRecordId;
    }

    // 成功的响应，带有同步记录 ID
    public static ApiResponse succeed(String syncRecordId) {
        return new ApiResponse("01", "推送成功","", syncRecordId);
    }

    // 失败的响应，带有同步记录 ID
    public static ApiResponse error(String syncRecordId) {
        return new ApiResponse("02", "推送失败", "",syncRecordId);
    }
    public static ApiResponse succee(String syncRecordId) {
        return new ApiResponse("01", "已有该账户", "",syncRecordId);
    }
    // 请求成功，返回数据
    public static ApiResponse succeed(Object retData) {
        return new ApiResponse(1001, "请求成功！", retData);
    }

    // 请求成功，但无数据
    public static ApiResponse succeedNoData() {
        return new ApiResponse(1001, "请求成功，但无数据！");
    }

    // 请求失败
    public static ApiResponse succeedRequestNo() {
        return new ApiResponse(1002, "请求失败！");
    }
    public static ApiResponse succeedRequestErr(Object retData) {
        return new ApiResponse(1002, "请求失败！",retData);
    }
    // 请求成功，无数据内容
    public static ApiResponse succeedRequest() {
        return new ApiResponse(1001, "请求成功！");
    }
}
